#include "card.h"

Card::Card(std::string cardName, int weight, int color)
    :m_cardName(cardName), m_weight(weight), m_color(color)
{

}

CardManager::CardManager()
{
    InitCard();
    Shuffle();
}

void CardManager::InitCard()
{
    m_cards.clear();
    for(int color = 0; color <= 3; color++)
    {
        for(int weight = 2; weight <= 14; weight++)
        {
            std::string cardName = "card_" + std::to_string(color) + "_" +  std::to_string(weight);
            Card::ptr card = std::make_shared<Card>(cardName, weight, color);
            m_cards.push_back(card);
        }
    }
}

void CardManager::Shuffle()
{
    size_t sum = m_cards.size();
    for (size_t i = 0; i < m_cards.size(); i++)
    {
        int num = std::rand() % sum;
        Card::ptr temp = m_cards[num];
        m_cards[num] = m_cards[i];
        m_cards[i] = temp;
    }
}

Card::ptr CardManager::DealCard()
{
    Card::ptr card = m_cards[0];
    m_cards.erase(m_cards.begin());
    return card;
}